<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
   <% String path=request.getContextPath(); 
   String basePath=request.getScheme()
    + "://" + request.getServerName() + ":" + request.getServerPort() + path
    + "/"; 

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href="<%=basePath%>">
<title>参数配置</title>
<link rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css">
<jsp:include page="/WEB-INF/jsp/common/common.jsp"></jsp:include>
<script type="text/javascript" src="<%=path%>/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="<%=path%>/js/jquery.ztree.excheck-3.5.js"></script>
<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>

<script>
$(document).ready(function() {
	loadConfig();
});

 
 
/**
 * 页面初始化查询显示所有系统配置列表
 */
function loadConfig(){
	$.openLoading();
	$.ajax({
		url : "<%=path%>/systemManager/queryList",
		type : 'POST',
		async : true,
		dataType:'json',
		success:function(configPage){
			$.closeLoading();
			//业务处理
			if(null != configPage){
				var buttonStr = "<a href='javascript:void(0)' onClick='editConfig(this);return false'>编辑</a>&nbsp;<a href='javascript:void(0)' onClick='warnDel(this)'>删除</a>&nbsp";
				var fieldNames = "configName,configValue,configDesc,user_name,operTimeStr";
				var tableContent = creatTable(fieldNames,configPage,buttonStr);
				var tableObj = $("#configTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
			}
		}
	});
}

//打开添加窗口
function openAddConfigDIV(){
	$('#configNameDiv').css("display","inline");
	$("#configNameSpan").css("display","none");
	$("#configName").val("");
	$('#configValue').val("");
	$('#configDesc').val("");
	$("#configDiv").OpenDiv();
	$("#saveConfigBtn").attr("onclick","").unbind("click").click(function(){  
		addConfig();
	}) 	
}

//添加
function addConfig(){
	var configName = $.trim($('#configName').val());
	var configValue = $.trim($('#configValue').val());
	var configDesc = $.trim($('#configDesc').val());
	if(configName.length==0){
		$.message("error","参数名称不能为空");
		return;
	}
	if(configValue.length==0){
		$.message("error","参数值不能为空");
		return;
	}
	if(configDesc.length==0){
		$.message("error","参数描述不能为空");
		return;
	}
	$.openLoading();
	$.ajax({
		url : "<%=path%>/systemManager/addConfig",
		type : 'POST',
		async : true,
		data:{
			configName:configName,
			configValue:configValue,
			configDesc:configDesc
			},
		dataType:'json',
		success:function(data){
			$.closeLoading();
			if(data!=null && data.result == "error"){
				$.message("error",data.message);
			}else{
				if($.validate(data))return;
				//添加成功后重新加载页面
				closeCurrentDIV('configDiv');
				//重新加载页面
				loadConfig();
				setTimeout("refreshFacadeCaches()",2000);//延迟2刷新界面出单系统的缓存
			}
		}
	});
}
//编辑
 function  editConfig(obj){
	 var delTr = $(obj).parent('td').parent('tr')[0]; 
	 var configName = delTr.childNodes[0].innerHTML;
	 var configValue = delTr.childNodes[1].innerHTML;
	 var configDesc = delTr.childNodes[2].innerHTML;
	 $("#configNameSpan").html(configName);
	 $('#configName').val(configName);
	 $("#configNameSpan").css("display","inline");
	 $('#configNameDiv').css("display","none");
	 $('#configValue').val(configValue);
	 $('#configDesc').val(configDesc);
	 $("#configDiv").OpenDiv();
	 $("#saveConfigBtn").attr("onclick","").unbind("click").click(function(){  
			saveConfig();
		}) 
	 
 }

 //保存修改
 function saveConfig(){
	 if(!checkBeforeAdd()) return;
	    var saveName = $.trim($('#configName').val());
	 	var saveValue = $.trim($('#configValue').val());
		var saveDesc = $('#configDesc').val();
		$.openLoading();
		$.ajax({
			url: "<%=path%>/systemManager/editConfig",
			type: "post",
			dataType: "json",
			data:{
				configName:saveName,
				configValue:saveValue, 
				configDesc:saveDesc
				},
			async:true,
			cache:false,
			success: function(data) {
				$.closeLoading();
				if(data!=null && data.result == "error"){
				$.message("error",data.message);
			    } else if(data!=null && data.result == "fail"){
			    $.message("fail",data.message);
			     closeCurrentDIV('configDiv');
			     window.parent.location.href ="<%=path%>/logout";
			     setTimeout("refreshFacadeCaches()",2000);//延迟2刷新界面出单系统的缓存
			   }else{
				  $.message("success", data.message);
				 //修改保存成功后重新加载页面
				  closeCurrentDIV('configDiv');
				 loadConfig();  
				 setTimeout("refreshFacadeCaches()",2000);//延迟2刷新界面出单系统的缓存
			   }
				
			}
		});
 }
 
//添加之前校验
 function checkBeforeAdd(){
 	var checkName= $.trim($('#configName').val());
 	var checkValue = $.trim($('#configValue').val());
 	var checkDesc = $.trim($('#configDesc').val());

 	if(checkValue.length==0){
 		$.message("error","参数值不能为空");
 		return false;
 	}
 	if(checkDesc.length==0){
 		$.message("error","参数描述不能为空");
 		return false;
 	}
 		return true;
 }

//删除之前 弹出提示框
function warnDel(obj){
	$.dialog({
		type: "warn",
		content: "确定要删除该参数配置吗？",
		onOk: function() {
			delConfig(obj);
		}
	});
}

 function delConfig(obj){
	 var delTr = $(obj).parent('td').parent('tr')[0];
	 var configName = delTr.childNodes[0].innerHTML;
		$.openLoading();
		$.ajax({
			url : "<%=path%>/systemManager/deleteConfig",
			type : 'POST',
			async : true,
			data:{"configName":configName},
			dataType:'json',
			success:function(data){
				$.closeLoading();
				if($.validate(data))return;
				loadConfig();
				setTimeout("refreshFacadeCaches()",2000);//延迟2刷新界面出单系统的缓存
			}
		});
	 
	 
 }
 
 function refreshCache(){
	 $.openLoading();
	 $.ajax({
			url : "<%=path%>/systemManager/refreshConfig",
			type : 'POST',
			async : true,
			dataType:'json',
			success:function(data){
				$.closeLoading();
				$.validate(data);
				loadConfig();
				setTimeout("refreshFacadeCaches()",2000);//延迟2刷新界面出单系统的缓存
			}
		});
 }
  
//关闭  窗口
function closeCurrentDIV(obj){
		$("#"+obj).CloseDiv();	
}
//刷新界面出单系统的缓存
function refreshFacadeCaches(){
	$.ajax({
	  type: "POST",
	  url: "<%=path%>/systemManager/refreshFacadeCaches",
	  dataType:'json',
	  success: function(data){
	    if(data.result=='success'){ 
	    	$.message("success",data.message);
	    }else if(data.result=='empty'){ 
	    	$.message("error",data.message);
	    }else{
	    	var url = '';
	    	for(var o in data.data){
				url+=data.data[o].url+";";
	    	}
	    	$.message("error",'以下界面出单系统缓存刷新失败：</br>'+url);
	    }
	    
	  }
	});
} 
</script>
</head>

<body>
	<div class="current">
           <table class="current_table_1">
              <tbody><tr class="f2">
                <td><img src="./images/current_1.jpg"></td>
                  <td class="current_table_1_td">
                  <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                  <span style=" color:#136bab; ">系统管理
                  <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>参数配置
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody>
           </table>
      </div>

	<%--显示系统配置的表格 --%>
	<table border="1" class="table_02" style="height:150px">
  		<tr height="50px">
  			<td style="text-align:left;" colspan="5" width="100%" height="30%">
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="addBtn" class="input_button_1"  value="新增" onclick="openAddConfigDIV()"/>
				<input type="button" id="queryBtn" class="input_button_4" value="刷新缓存" onclick="refreshCache(1)"/>&nbsp;&nbsp;
			</td>
  		</tr>
  		<tr>
  			<td valign="top">
	  			<div id="configDIV" style="width:98%;margin:5px">
			  		<table class="table_02" id="configTable">
			  		<thead>
		              <tr>
		                  <th style="width:19%">参数名称</th>
		                  <th style="width:17%">参数值</th>
		                  <th style="width:17%">参数描述</th>
		                  <th style="width:17%">操作人</th>
		                  <th style="width:17%">操作时间</th>
		                  <th style="width:17%">操作</th>
		              </tr>
		              </thead>
		              <tbody>
					  </tbody>
		            </table>
	  			</div>
  			</td>
  		</tr>
  	</table>
  		<!--   	添加、修改配置DIV 默认隐藏-->
  		<div id="configDiv" style="display:none;width:400px;">
		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('configDiv')"/></td>
						</tr>
					</table>
		</div>
		<table class="table_02" id="saveConfigTable" style="height:100px;width: 95%" align="center" >
			<tr>
				<td style="text-align:right;border-right:0px;" width="30%" >参数名称：</td> 
				<td style="text-align:left;border-right:0px;" width="45%">
				   	<div id="configNameDiv" >
				   		 <input  type="text" id="configName"  class="input_text">
				   		 <span class="red">*</span>
				    </div>
				    <span class="red" id="configNameSpan"></span>
				</td>
				<td width="25%" style="text-align:left;">&nbsp;&nbsp;<span id="configerror"></span></td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="30%" >参数值：</td>
				<td style="text-align:left;border-right:0px;" width="40%"> 
				  <input type="text" id="configValue" class="input_text" >
				  <span class="red">*</span>
				  </td>
				<td width="30%" style="text-align:left;">&nbsp;&nbsp;<span id="configValueError"></span></td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="30%" >参数描述：</td>
				<td style="text-align:left;border-right:0px;" width="40%"> 
				<input type="text" id="configDesc" class="input_text">
				 <span class="red">*</span>
				</td>
				<td width="30%" style="text-align:left;">&nbsp;&nbsp;<span id="configDescError"></span></td>
			</tr>
		</table>
		<div style="width: 95%;height:30px;" align="center">
		   <input type="button" id="saveConfigBtn" value="保存" onclick="addConfig()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
	       <input type="button" value="取消" onclick="closeCurrentDIV('configDiv')" class="input_button_3"/>
		</div>
	</div>
	
 
  
 
</body>
</html>
